<?php


namespace app\common\model;


use think\Model;

class UserMoneyLog extends Model
{
    public static function saveLog($user_id,$type,$value,$order_id='',$order_sn='',$remark=''){
        $user = User::where('id',$user_id)->find();
        if ($type == 'inc'){
            $after = $user['money'] + $value;
        }else{
            $after = $user['money'] - $value;
        }
        self::create([
            'user_id'=>$user_id,
            'type'=>$type,
            'before'=>$user['money'],
            'value'=>$value,
            'after'=>$after,
            'order_id'=>$order_id,
            'order_sn'=>$order_sn,
            'remark'=>$remark,
        ]);
    }
}
